package cross;

import individuals.Individual;

import java.util.ArrayList;
import java.util.List;

public class ClassicCross implements Cross{
	
	private long allBits= 0xFFFFFFFFFFFFFFFFL;
	
	public List<Individual> Apply(Individual father, Individual mother) {
		List<Individual> list = new ArrayList<Individual>();
		
		int indexCut = (int) Math.floor(Cross.ranGen.nextDouble()*64);
		
		long mask = allBits>>>(64-indexCut);
		long mask1 = mask;
		long mask2 = mask;
		
		mask1 &= Double.doubleToRawLongBits(father.getGen());
		mask2 &= Double.doubleToRawLongBits(mother.getGen());
		
		mask = ~mask;
		Double son1 = Double.longBitsToDouble((Double.doubleToRawLongBits(father.getGen())&mask)|mask2);
		Double son2 = Double.longBitsToDouble((Double.doubleToRawLongBits(mother.getGen())&mask)|mask1);
		list.add(new Individual(son1));
		list.add(new Individual(son2));
		
		return list;
	}
}
